package classes;

import java.util.HashMap;
import java.util.HashSet;

public class PlayerCharacter {
	//
	// This is the place we will define the model for a character. This may also apply to monsters
	//
	
	public final HashMap<Ability, Integer>	ability = new HashMap<Ability, Integer>();
	public final HashSet<Ability>			proficientSaves = new HashSet<Ability>(); 

	private Class	charClass;
	private Race	race;
	
	private int xp;			// level of the player
	private int	hdSize;		// Size of each hd
	private int hdUsed;		// Number of hd spent this day
	private int dmg;		// Damage ont eh character
	private int tmpHp;		// Temporary hp of the character
	
	private Ability	spellAbility = Ability.INT;


	public void setAbility(Ability abil, int value) {	ability.put(abil, new Integer(value));									}
	
	public int 		getAbility(Ability abil)		{	return ability.get(abil).intValue();									}
	public int 		getLevel()						{	return (int) Math.floor( (1+Math.sqrt(getXp()/125 + 1))/2 );			}
	public int 		getProf()						{	return (5 * getLevel())/4;												}
	public int 		getMod(Ability abil)			{	return (getAbility(abil)/2) - 10;										}
	public int 		getSpellDc()					{	return 8 + getMod(getSpellAbility()) + getProf();						}
	public int 		getAvgHdValue()					{	return getHdSize()/2 + 1;												}
	public boolean	isSaveProficiency(Ability abil)	{	return proficientSaves.contains(abil);									}
	public int		getSaveBonus(Ability abil)		{	return getMod(abil) + ((isSaveProficiency(abil)) ? getProf() : 0);		}
	public int		getAvgLootDropInCp()			{	return getLevel() * 1250;												}

	
	public int 		getAvgMaxHp()		{	return getHdSize() + getMod(Ability.CON) + (getLevel()-1) * (getAvgHdValue() + getMod(Ability.CON));	}
	
	//
	// Getters and Setters
	//
	
	public int getHdSize() {
		return hdSize;
	}
	public void setHdSize(int hdSize) {
		this.hdSize = hdSize;
	}

	public int getHdUsed() {
		return hdUsed;
	}
	public void setHdUsed(int hdUsed) {
		this.hdUsed = hdUsed;
	}

	public int getXp() {
		return xp;
	}
	public void setXp(int xp) {
		this.xp = xp;
	}

	public int getDmg() {
		return dmg;
	}
	public void setDmg(int dmg) {
		this.dmg = dmg;
	}

	public int getTmpHp() {
		return tmpHp;
	}
	public void setTmpHp(int tmpHp) {
		this.tmpHp = tmpHp;
	}

	public Ability getSpellAbility() {
		return spellAbility;
	}
	public void setSpellAbility(Ability spellAbility) {
		this.spellAbility = spellAbility;
	}

	public Class getCharClass() {
		return charClass;
	}

	public void setCharClass(Class charClass) {
		this.charClass = charClass;
	}

	public Race getRace() {
		return race;
	}

	public void setRace(Race race) {
		this.race = race;
	}

	//
	// Internal enumerations
	//
	public enum Ability {
		STR, DEX, CON, INT, WIS, CHA
	}
	public enum Race {
		human, elf, dwarf, halfling
	}
	public enum Class {
		fighter, cleric, theif, mage
	}
	
}
